/**
 *  buf.h - A shared buffer and related calls.
 *
 *  Copyright (C) 2008-2010 ZhangHu
 *  All rights reserved.
 *  E-MAIL: anmnmnly@gmail.com
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
#ifndef __BUF_H__
#define __BUF_H__

#include "include/types.h"
#ifndef UNIT_DEBUG
#include "include/mem.h"
#include "include/core.h"
#endif


typedef struct buffer {
    uint32 size;    // size of shared buffer
    uint32 used;    // used space of shared buffer
    char_t *start;   // pointer to start postion of shared buffer
    char_t *end;     // pointer to end postion of shared buffer
    char_t *inpos;   // pointer to postion where new data will be writen
    char_t *outpos;  // pointer to postion where data will read
}buf_t;



// APIs for operating buffer.
extern buf_t *bufInit(uint32 BufSize);
extern bool_t bufSend(buf_t *pBuf, char_t ch);
extern uint32 bufSendArray(buf_t *pBuf, const char_t *Buf, int32 Len);
extern char_t bufRev(buf_t *pBuf, bool_t *Err);
extern uint32 bufRevArray(buf_t *pBuf, char_t *Buf, int32 Len);
extern int32 bufGetUsed(const buf_t *pBuf);
extern void bufClear(buf_t *pBuf);
extern void bufDel(buf_t *pBuf);


#endif

